package com.xxq.semester.entity.utils;

import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

@Setter
@Getter
public class ResponseEntity<T> {
    // Getters and Setters
    private Integer code;
    private String message;
    private T data;
    private LocalDateTime timestamp;

    public ResponseEntity() {
        this.timestamp = LocalDateTime.now();
    }

    public ResponseEntity(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.timestamp = LocalDateTime.now();
    }

    // 成功响应
    public static <T> ResponseEntity<T> success(T data) {
        return new ResponseEntity<>(200, "操作成功", data);
    }

    public static <T> ResponseEntity<T> success(String message, T data) {
        return new ResponseEntity<>(200, message, data);
    }

    public static ResponseEntity<String> success(String message) {
        return new ResponseEntity<>(200, message, null);
    }

    // 失败响应
    public static <T> ResponseEntity<T> fail(String message) {
        return new ResponseEntity<>(400, message, null);
    }

    public static <T> ResponseEntity<T> fail(Integer code, String message) {
        return new ResponseEntity<>(code, message, null);
    }

    // 未授权
    public static <T> ResponseEntity<T> unauthorized(String message) {
        return new ResponseEntity<>(401, message, null);
    }

    // 禁止访问
    public static <T> ResponseEntity<T> forbidden(String message) {
        return new ResponseEntity<>(403, message, null);
    }

    // 服务器错误
    public static <T> ResponseEntity<T> error(String message) {
        return new ResponseEntity<>(500, message, null);
    }
    public static <T> ResponseEntity<T> notfound(String message) {
        return new ResponseEntity<>(404, message, null);
    }

}
